package dbms;

public class Type {
	public static final int BOOLEAN = 0, INTEGER = 1, FLOAT = 2, DOUBLE = 3, STRING = 4;

	public static Class getTypeClass(int type) {
		if (type == BOOLEAN)
			return new Boolean(false).getClass();
		if (type == INTEGER)
			return new Integer(0).getClass();
		if (type == FLOAT)
			return new Float(0).getClass();
		if (type == DOUBLE)
			return new Double(0).getClass();
		if (type == STRING)
			return new String("").getClass();
		return new Object().getClass();
	}

	public static String getTypeName(int type) {
		if (type == BOOLEAN)
			return "Boolean";
		if (type == INTEGER)
			return "Integer";
		if (type == FLOAT)
			return "Float";
		if (type == DOUBLE)
			return "Double";
		if (type == STRING)
			return "String";
		return "";
	}

	public static int getTypeID(String typeName) {
		if (typeName.equalsIgnoreCase("Boolean"))
			return BOOLEAN;
		if (typeName.equalsIgnoreCase("Integer"))
			return INTEGER;
		if (typeName.equalsIgnoreCase("Float"))
			return FLOAT;
		if (typeName.equalsIgnoreCase("Double"))
			return DOUBLE;
		if (typeName.equalsIgnoreCase("String") || typeName.contains("VARCHAR"))
			return STRING;
		return 0;
	}

	public static Object parse(String text, int type) {
		if (type == BOOLEAN)
			return Boolean.parseBoolean(text);
		if (type == INTEGER)
			return Integer.parseInt(text);
		if (type == FLOAT)
			return Float.parseFloat(text);
		if (type == FLOAT)
			return Double.parseDouble(text);
		if (type == STRING)
			return text;
		return null;
	}

	public static Object getDefault(int type) {
		if (type == BOOLEAN)
			return new Boolean(false);
		if (type == INTEGER)
			return new Integer(0);
		if (type == FLOAT)
			return new Float(0);
		if (type == DOUBLE)
			return new Double(0);
		if (type == STRING)
			return new String("");
		return null;
	}
}
